package com.zmn.plat.admin.controller.extension.serv.category.group;

import javax.servlet.http.HttpServletRequest;

import com.zmn.plat.common.exception.PlatException;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.zmn.common.dto2.ResponseDTO;

/**
 * 服务推广分类-推广分类关联
 *
 * @author linfeng
 * @since 2019-12-24 10:55:48
 */
@RestController
@RequestMapping("/extension/serv/category/group/")
public class ExtensionServCategoryGroupModifyController extends ExtensionServCategoryGroupBaseController {

    @PostMapping(value = "batchAddAssociation")
    @RequiresPermissions("/extension/serv/category/group/batchAddAssociation.action")
    @ResponseBody
    public ResponseDTO batchAddAssociation(HttpServletRequest request, @RequestBody JSONObject object) {
        try {
            Integer result = extensionServCategoryGroupBService.batchAddAssociation(getMcStaffRealName(), object);
            return ResponseDTO.success(result, "保存成功！");
        }catch (PlatException e){
            return ResponseDTO.fail(e.getMessage());
        }catch (Exception e){
            return ResponseDTO.fail("操作失败");
        }

    }

    @PostMapping(value = "batchRelateBackCategory")
    @RequiresPermissions("/extension/serv/category/group/batchRelateBackCategory.action")
    @ResponseBody
    public ResponseDTO batchRelateBackCategory(HttpServletRequest request, @RequestBody JSONObject object) {
        try {
            Integer result = extensionServCategoryGroupBService.batchRelateBackCategory(getMcStaffRealName(), object);;
            return ResponseDTO.success(result, "保存成功！");
        }catch (PlatException e){
            return ResponseDTO.fail(e.getMessage());
        }catch (Exception e){
            return ResponseDTO.fail("操作失败");
        }
    }

    @RequestMapping(value = "delete")
    @RequiresPermissions("/extension/serv/category/group/delete.action")
    @ResponseBody
    public ResponseDTO delete(@RequestParam(value = "ids", defaultValue = "0") String servCategIdAndExtensionCategIds) {
        if (StringUtils.isEmpty(servCategIdAndExtensionCategIds)) {
            return ResponseDTO.fail("请选择要删除的数据！");
        }

        Integer result =
            extensionServCategoryAssociationService.deleteByServCategIdAndExtensionCategId(servCategIdAndExtensionCategIds.split(","));
        return ResponseDTO.success(result, "操作成功！");
    }
}
